package com.jishe.controller;

import com.jishe.pojo.Result;
import com.jishe.pojo.User;
import com.jishe.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RequestMapping("/users")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping
    //增
    public Result save(@RequestBody User user){
        log.info("新增用户:{}", user);
        userService.save(user);
        return Result.success();
    }
    //删
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        userService.delete(ids);
        return Result.success();
    }
    //条件查询根据用户名，性别和
    @GetMapping
    public Result list(String username, Short gender){
        log.info("接收到查询请求: username={}, gender={}", username, gender);
        List<User> userList = userService.list(username, gender);
        return Result.success(userList);
    }
}
